package cn.yqx.bankshop.user.controller;

import cn.yqx.bankshop.result.Result;
import cn.yqx.bankshop.result.ResultCode;
import cn.yqx.bankshop.user.pojo.BuUserInfo;
import cn.yqx.bankshop.user.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/api/v1/user")
@Slf4j
public class UserController {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;

    @Autowired
    UserInfoService userInfoService ;
    @RequestMapping(value = "/find-userinfo-by-userid")
    public Object findUserInfoByUserid(Long userId){
        return  userInfoService.selectByUserId(userId) ;
    }
    @RequestMapping(value = "find_userinfo_by_userid")
    public Object findUserInfoByUseridApi(Long userId){
        Result result ;
        try{

            result = Result.success() ;
            BuUserInfo userInfo = userInfoService.selectByUserIdNoPassword(userId) ;
            result.setData(userInfo);

        }catch (Exception e) {
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR) ;
            log.info(" error : {} ",e);
        }
        return result ;

    }

    @RequestMapping(value = "edit_userinfo_by_userid" , method = RequestMethod.POST)
    public Object editUserinfoByUserid(@RequestBody BuUserInfo userInfo , String borthTime ){
        log.info("userInfo : {} " , userInfo);
        if(!StringUtils.isEmpty(borthTime)){

        }
        Result result ;
        try{
            result = Result.success() ;
            int flag =  userInfoService.editUserinfoByUserid(userInfo) ;
            if(flag < 0 ){
                result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR) ;
            }

        }catch (Exception e) {
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR) ;
            log.info(" error : {} ",e);
        }
        return result ;

    }
}
